-
-
Notifications
You must be signed in to change notification settings - Fork 69
Add API to sort array of custom objects #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/x86simdsort.h
Outdated
#define UNUSED(x) (void)(x) | ||
|
||
template <typename T> | ||
XSS_HIDE_SYMBOL void permute_array_in_place(T *A, std::vector<size_t> P) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to an x86simdsort::detail
namespace.
Take the P
parameter by const-reference or change the call site to use std::move(arg)
.
using return_type_of = | ||
typename decltype(std::function {key_func})::result_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a C++17 technique (CTAD). If you need to support pre-C++17, you may need to rewrite it.
{ | ||
using return_type_of = | ||
typename decltype(std::function {key_func})::result_type; | ||
std::vector<return_type_of> keys; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: keys.reserve(arrsize)
.
lib/x86simdsort.h
Outdated
|
||
// sort an object | ||
template <typename T, typename F> | ||
XSS_EXPORT_SYMBOL void object_qsort(T *arr, size_t arrsize, const F key_func) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more idiomatic in C++ if you did:
template <typename It, typename F> void object_qsort(It begin, It end, F &&key_func)
{
using T = typename std::iterator_traits<It>::value_type;
#if __cplusplus >= 201703L
using R = std::invoke_result_t<F, T>;
#else
using R = std::result_of_t<F>;
#endif
std::vector<R> keys;
keys.reserve(std::distance(begin, end));
for (auto it = first; it != end; ++it)
keys.emplace_back(key_func(*it));
e680504
to
fbc033e
Compare
Benchmarks sorting an array of 2D and 3D cartesian coordinates: